package volleyball.model;


/**
 * Creates a Player. Players have a name and all the 
 * Statistics that can happen in a volleyball game. A 
 * Player object can be used to store every action that 
 * a Player can make in a Game.
 * @author Joshua Kulhavy-Sutherland
 *
 */
public class Player {
	//TODO something about this. Have you ever heard of a data structure you idiot!
	private String name;
	private Statistic serve;
	private Statistic serveError;
	private Statistic serveAce;
	private Statistic set;
	private Statistic ballHandlingError;
	private Statistic pass0;
	private Statistic pass1;
	private Statistic pass2;
	private Statistic pass3;
	private Statistic attackKill;
	private Statistic attackError;
	private Statistic attackAttempt;
	private Statistic dig;
	private Statistic block;
	private Statistic blockAttempt;
	private Statistic blockError;
	private Statistic assist;
	
	/**
	 * Creates a player with a name and every Statistic in a volleyball game
	 */
	public Player(String name) {
		//TODO is this needed, since a name of null would not activate this constructor right?
		if (name==null)
			throw new NullPointerException();
		this.name         = name.trim();
		serve             = new Statistic();
		serveError        = new Statistic();
		serveAce          = new Statistic();
		set               = new Statistic();
		ballHandlingError = new Statistic();
		pass0             = new Statistic();
		pass1             = new Statistic();
		pass2             = new Statistic();
		pass3             = new Statistic();
		attackKill        = new Statistic();
		attackError       = new Statistic();
		attackAttempt     = new Statistic();
		dig               = new Statistic();
		block             = new Statistic();
		blockAttempt      = new Statistic();
		blockError        = new Statistic();
		assist            = new Statistic();
	}
	
	/**
	 * Returns the players name
	 * @return
	 */
	public String getName(){
		return name;
	}
	
	/**
	 * Returns a printout of this Player's name and all the Statistics contained in this Player
	 */
	public String toString(){
		return "Name: "+name+" has [Serve: "+serve.getSize()+" ServeAce: "+serveAce.getSize()+" ServeError: "+serveError.getSize()
				+" Set: "+set.getSize()+" Assist: "+assist.getSize()+" BallHandlingError: "+ballHandlingError.getSize()+
				" Pass0: "+pass0.getSize()+" Pass1: "+pass1.getSize()+" Pass2: "+pass2.getSize()+" Pass3: "+pass3.getSize()
				+" AttackKill: "+attackKill.getSize()+" AttackError: "+attackError.getSize()+" AttackAttempt: "+attackAttempt.getSize()
				+" Dig: "+dig.getSize()+" Block: "+block.getSize()+" BlockAttempt: "+blockAttempt.getSize()+" BlockError: "+blockError.getSize()
				+"]";
	}
	
	/**
	 * @param name Sets the name of this Player to this
	 */
	public void setName(String name){
		this.name = name; 
	}
	
	

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	/**
	 * Any two Players with the same name will have equal hashCodes
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	/**
	 * Any two players with the same name will be equal.
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Player other = (Player) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}

	/**
	 * @return the players total number of serves
	 */
	public int getTotalServe() {
		return serve.getSize();
	}
	
	/**
	 * @return a String of all the times a serve took place
	 */
	public String getServe() {
		return serve.toString();
	}

	/**
	 * @param time add this time to this Statistic
	 */
	public void addServe(float time){
		serve.addStat(time);
	}
	
	/**
	 * @return a String of all the times a serve error took place
	 */
	public String getServeError() {
		return serveError.toString();
	}
	
	/**
	 * @return the players total number of service errors.
	 */
	public int getTotalServeError(){
		return serveError.getSize();
	}
	
	/**
	 * @param time add this time to this Statistic
	 */
	public void addServeError(float time){
		serveError.addStat(time);
	}
	
	/**
	 * @return a String of all the times a serve ace took place
	 */
	public String getServeAce(){
		return serveAce.toString();
	}
	
	/**
	 * @return the players total number of service aces
	 */
	public int getTotalServeAce() {
		return serveAce.getSize();
	}
	
	/**
	 * @param time add this time to this Statistic
	 */
	public void addServeAce(float time){
		serveAce.addStat(time);
	}

	/**
	 * @return a String of all the times a set took place
	 */
	public String getSet() {
		return set.toString();
	}
	
	/**
	 * @return the players total number of sets
	 */
	public int getTotalSet(){
		return set.getSize();
	}
	
	/**
	 * @param time add this time to this Statistic
	 */
	public void addSet(float time){
		set.addStat(time);
	}

	/**
	 * @return a String of all the times a ball handling error took place
	 */
	public String getBallHandlingError() {
		return ballHandlingError.toString();
	}
	
	/**
	 * @return the players total number of ball handling errors
	 */
	public int getTotalBallHandlingError(){
		return ballHandlingError.getSize();
	}
	
	/**
	 * @param time add this time to this Statistic
	 */
	public void addBallHandlingError(float time){
		ballHandlingError.addStat(time);
	}

	/**
	 * @return a String of all the times a pass 0 took place
	 */
	public String getPass0() {
		return pass0.toString();
	}
	
	/**
	 * @return the players total number of pass 0's
	 */
	public int getTotalPass0(){
		return pass0.getSize();
	}
	
	/**
	 * @param time add this time to this Statistic
	 */
	public void addPass0(float time){
		pass0.addStat(time);
	}

	/**
	 * @return a String of all the times a pass 1 took place
	 */
	public String getPass1() {
		return pass1.toString();
	}
	
	/**
	 * @return the players total number of pass 1's
	 */
	public int getTotalPass1(){
		return pass1.getSize();
	}
	
	/**
	 * @param time add this time to this Statistic
	 */
	public void addPass1(float time){
		pass1.addStat(time);
	}

	/**
	 * @return a String of all the times a pass 2 took place
	 */
	public String getPass2() {
		return pass2.toString();
	}
	
	/**
	 * @return the players total number of pass 2's
	 */
	public int getTotalPass2(){
		return pass2.getSize();
	}
	
	/**
	 * @param time add this time to this Statistic
	 */
	public void addPass2(float time){
		pass2.addStat(time);
	}

	/**
	 * @return a String of all the times a pass 3 took place
	 */
	public String getPass3() {
		return pass3.toString();
	}
	
	/**
	 * @return the players total number of pass 3's
	 */
	public int getTotalPass3(){
		return pass3.getSize();
	}
	
	/**
	 * @param time add this time to this Statistic
	 */
	public void addPass3(float time){
		pass3.addStat(time);
	}

	/**
	 * @return a String of all the times an attack kill took place
	 */
	public String getAttackKill() {
		return attackKill.toString();
	}

	/**
	 * @return the players total number of attack kills
	 */
	public int getTotalAttackKill(){
		return attackKill.getSize();
	}
	
	/**
	 * @param time add this time to this Statistic
	 */
	public void addAttackKill(float time){
		attackKill.addStat(time);
	}
	
	/**
	 * @return a String of all the times an attack error took place
	 */
	public String getAttackError() {
		return attackError.toString();
	}
	
	/**
	 * @return the players total number of attack errors
	 */
	public int getTotalAttackError(){
		return attackError.getSize();
	}

	/**
	 * @param time add this time to this Statistic
	 */
	public void addAttackError(float time){
		attackError.addStat(time);
	}
	
	/**
	 * @return a String of all the times an attack attempt took place
	 */
	public String getAttackAttempt() {
		return attackAttempt.toString();
	}
	
	/**
	 * @return the players total number of attack attempts
	 */
	public int getTotalAttackAttempt(){
		return attackAttempt.getSize();
	}
	
	/**
	 * @param time add this time to this Statistic
	 */
	public void addAttackAttempt(float time){
		attackAttempt.addStat(time);
	}

	/**
	 * @return a String of all the times a dig took place
	 */
	public String getDig() {
		return dig.toString();
	}
	
	/**
	 * @return the players total number of digs
	 */
	public int getTotalDig(){
		return dig.getSize();
	}
	
	/**
	 * @param time add this time to this Statistic
	 */
	public void addDig(float time){
		dig.addStat(time);
	}

	/**
	 * @return a String of all the times a block took place
	 */
	public String getBlock() {
		return block.toString();
	}
	
	/**
	 * @return the players total number of blocks
	 */
	public int getTotalBlock(){
		return block.getSize();
	}
	
	/**
	 * @param time add this time to this Statistic
	 */
	public void addBlock(float time){
		block.addStat(time);
	}

	/**
	 * @return a String of all the times a block attempt took place
	 */
	public String getBlockAttempt() {
		return blockAttempt.toString();
	}
	
	/**
	 * @return the players total number of block attempts
	 */
	public int getTotalBlockAttempt(){
		return blockAttempt.getSize();
	}
	
	/**
	 * @param time add this time to this Statistic
	 */
	public void addBlockAttempt(float time){
		blockAttempt.addStat(time);
	}

	/**
	 * @return a String of all the times a block error took place
	 */
	public String getBlockError(){
		return blockError.toString();
	}
	
	/**
	 * @return the players total number of block errors
	 */
	public int getTotalBlockError(){
		return blockError.getSize();
	}
	
	/**
	 * @param time add this time to this Statistic
	 */
	public void addBlockError(float time){
		blockError.addStat(time);
	}
	
	/**
	 * @return a String of all the times an assist took place
	 */
	public String getAssist(){
		return assist.toString();
	}
	
	/**
	 * @return the players total number of assists
	 */
	public int getTotalAssist(){
		return assist.getSize();
	}
	
	/**
	 * @param time add this time to this Statistic
	 */
	public void addAssist(float time){
		assist.addStat(time);
	}
}
